package org.example.springwebmvc.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.http.HttpRequest;

@RequestMapping("/session")
@RestController
public class SessionController {

//    Servlet 方式
    @RequestMapping("/getHeader")
    public String getHeader(HttpServletRequest request){
        String header = request.getHeader("User-Agent");
        return "从header中获取信息: "+header;
    }

//    Spring方式 通过注解
    @RequestMapping("/getHeader2")
    public String getHeader2(@RequestHeader("User-Agent") String u){
        return "从header中获取信息: "+ u;
    }
}
